package org.itboys.mobile.controller.mobile;

import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.mobile.entity.mongo.SundayAdvertisement;
import org.itboys.mobile.service.mongo.front.SundayFrontHelpService;
import org.itboys.mobile.service.mongo.web.SundayAdvertisementService;
import org.itboys.mobile.util.AccountIdHoldUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Created by zhangyang on 2018/1/3.
 * 圣代_帮助中心_controller_mobile
 */
@Controller
@RequestMapping("/sunday/mobile/help")
public class SundayMobileHelpController extends BaseController{


    @Autowired
    private SundayFrontHelpService helpService;
    @Autowired
    private SundayAdvertisementService advertisementService;

    /**
     * 主页
     */
    @ApiOperation(value="【手机端】帮助中心。H5页面直接加载网页")
    @RequestMapping(value="/index", method= {RequestMethod.GET,RequestMethod.POST})
    public String index(
            HttpServletRequest request,Model model){
        try{
          //  AccountIdHoldUtils.getSessionMember(request);
            //查询维护的帮助中心类别
            // SundayHelpCenterDto helpCenterDto = helpService.select();
            Map<String,Object> result =  helpService.getIndexData();
            //model.addAttribute("helpCenterDto",helpCenterDto);
            model.addAttribute("result",result);
            return "/aigou/mobile/help/index";
        }catch (Exception e){
            logger.error("/sunday/mobile/help/index----e="+e.getMessage());
            e.printStackTrace();
            return "/aigou/mobile/error";
        }
    }

    @RequestMapping(value="/html5",method={RequestMethod.GET,RequestMethod.POST})
    public String html5(
            Model model,
            @ApiParam(required=true, name="id")@RequestParam(value = "id",required = true) Long id){
        SundayAdvertisement help = advertisementService.getById(id);
        model.addAttribute("help",help);
        return "/aigou/mobile/help/html5";
    }
}
